package com.ruoyi.web.controller.coronary;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.coronary.domain.CoronarPatient;
import com.ruoyi.coronary.service.ICoronarPatientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 患者Controller
 *
 * @author wky
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/coronary/patient")
@Tag(name = "【患者】管理")
public class CoronarPatientController extends BaseController
{
    @Autowired
    private ICoronarPatientService coronarPatientService;

    /**
     * 查询患者列表
     */
    @Operation(summary = "查询患者列表")
    @PreAuthorize("@ss.hasPermi('coronary:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoronarPatient coronarPatient)
    {
        startPage();
        List<CoronarPatient> list = coronarPatientService.selectCoronarPatientList(coronarPatient);
        return getDataTable(list);
    }

    /**
     * 导出患者列表
     */
    @Operation(summary = "导出患者列表")
    @PreAuthorize("@ss.hasPermi('coronary:patient:export')")
    @Log(title = "患者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoronarPatient coronarPatient)
    {
        List<CoronarPatient> list = coronarPatientService.selectCoronarPatientList(coronarPatient);
        ExcelUtil<CoronarPatient> util = new ExcelUtil<CoronarPatient>(CoronarPatient.class);
        util.exportExcel(response, list, "患者数据");
    }

    /**
     * 获取患者详细信息
     */
    @Operation(summary = "获取患者详细信息")
    @PreAuthorize("@ss.hasPermi('coronary:patient:query')")
    @GetMapping(value = "/{patientId}")
    public AjaxResult getInfo(@PathVariable("patientId") Long patientId)
    {
        return success(coronarPatientService.selectCoronarPatientByPatientId(patientId));
    }

    /**
     * 新增患者
     */
    @Operation(summary = "新增患者")
    @PreAuthorize("@ss.hasPermi('coronary:patient:add')")
    @Log(title = "患者", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoronarPatient coronarPatient)
    {
        return toAjax(coronarPatientService.insertCoronarPatient(coronarPatient));
    }

    /**
     * 修改患者
     */
    @Operation(summary = "修改患者")
    @PreAuthorize("@ss.hasPermi('coronary:patient:edit')")
    @Log(title = "患者", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoronarPatient coronarPatient)
    {
        return toAjax(coronarPatientService.updateCoronarPatient(coronarPatient));
    }

    /**
     * 删除患者
     */
    @Operation(summary = "删除患者")
    @PreAuthorize("@ss.hasPermi('coronary:patient:remove')")
    @Log(title = "患者", businessType = BusinessType.DELETE)
	@DeleteMapping("/{patientIds}")
    public AjaxResult remove(@PathVariable( name = "patientIds" ) Long[] patientIds)
    {
        return toAjax(coronarPatientService.deleteCoronarPatientByPatientIds(patientIds));
    }
}
